//
//  BLEOperation.h
//  BLESDKDemo
//
//  Created by 李阳 on 2018/5/2.
//  Copyright © 2018年 李阳. All rights reserved.
//

#import <Foundation/Foundation.h>

/// 蓝牙操作类型
typedef NS_ENUM(NSUInteger, BLEOperationType) {
    BLEOperationTypeIdle, ///< 闲置，当前无操作
    BLEOperationTypeSearch, ///< 搜索设备
    BLEOperationTypeConnect, ///< 连接设备
    BLEOperationTypeDisconnect, ///< 主动断开设备连接
    BLEOperationTypeReadRSSI, ///< 读取信号强度
    BLEOperationTypePrepareSession, ///< 为和设备会话做准备(发现服务，特征等)
    BLEOperationTypeSession, ///< 和设备会话
};

/// 蓝牙操作类
@interface BLEOperation : NSObject

/// 类型
@property (nonatomic, assign) BLEOperationType type;

/// 超时时间
@property (nonatomic, assign) NSTimeInterval timeout;

/// 是否已经启动
@property (nonatomic, assign, readonly) BOOL hasFired;

/// 启动时的回调
@property (nonatomic, copy) void(^fireBlock)(BLEOperation *op, NSTimeInterval use);

/// 会调用 `fireBlock`, 如果定时器没开启则会开启
- (void)fire;

/// 销毁时的回调, 手动销毁和超时都会调用
@property (nonatomic, copy) void(^invalidateBlock)(BLEOperation *op, NSTimeInterval use, NSError *error);

- (void)invalidate;

/// 发生错误提前销毁，会回调`invalidateBlock`
- (void)invalidateWithError:(NSError *)error;


///
@property (nonatomic, copy) void(^scheduleBlock)(BLEOperation *op, NSTimeInterval use, id obj);
/// 会调用 `scheduleBlock` 在定时器有效期间内才有效
- (void)scheduleWithObject:(id)obj;


/// 开始定时器
- (void)start;


- (BOOL)isEqualToOperation:(BLEOperation *)op;

@end



